package com.example.demo.filter;

import com.example.demo.util.ConvertUtil;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.LogRecord;


@WebFilter
@Order(2)
@Component
public class TestFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

//        InputStream inputStream = new BufferedInputStream(request.getInputStream());
//        int available = inputStream.available();
//
//        System.out.println(ConvertUtil.inputStream2String(inputStream));
//        System.out.println("sdfa");
////
////        ServletInputStream is = request.getInputStream();
////        System.out.println(ConvertUtil.inputStream2String(is));
////        System.out.println("sdfsdf");
//
//
////        InputStreamCacher  cacher = new InputStreamCacher(inputStream);
////        InputStream stream = cacher.getInputStream();
//////读取stream
////        stream = cacher.getInputStream();
//
//        inputStream.mark(available + 1);
//        inputStream.reset();
//        BufferedReader reader = request.getReader();
////        int available = request.getInputStream().available();
//        System.out.println(ConvertUtil.string(reader));
//        reader.mark(8192);
//        reader.reset();
        chain.doFilter(request, response);

    }

    @Override
    public void destroy() {

    }
}
